/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#ifndef PARSEALL_H
#define PARSEALL_H

#include <Windows.h>
#include <tchar.h>
#include <list>
#include <string>
#include <smtptr.h>
#include <syntaxex.h>
#include "parse.h"
#include "parsenode.h"

//////////////////////////////////////////////////////////////
// Macros
/////////////////////////////////////////////////////////////
#define PARSE_DELIM L"~`!@#$%^&*()_={}[]|\\;;:<>?,./"
#define PARSE_COMMENT L'\''

/////////////////////////////////////////////////////////////
// ParseAll: Parses foward and backwards
/////////////////////////////////////////////////////////////
class ParseAll
{
public: // Construction
	ParseAll()
	{
		Init();
	}

	ParseAll(const ParseAll& rhs)
	{
		Init();
		Copy(rhs);
	}

public: // Methods
	void InitBuffer(const wchar_t *buffer); // Initializes buffer

	void InitDelim(const wchar_t *delim = PARSE_DELIM)
	{
		_parse->InitDelim(delim);
	}

	void InitComment(wchar_t com)
	{
		_parse->InitComment(com);
	}

public: // Methods
	SyntaxErr Prev()
	{
		// At beginning already?
		if (_w->is_begin)
			return SE_NONE;

		// Get previous word
		_w--;

		// Return error
		return _w->err;
	}

	SyntaxErr Next()
	{
		// At end already?
		if (_w->is_end)
			return SE_NONE;

		// Get next word
		_w++;

		// Return error
		return _w->err;
	}

public: // Accessor methods
	wstring GetBuffer() { return _parse->GetBuffer(); }
	wstring GetDelim() { return _parse->GetDelim(); }
	wchar_t GetComment() { return _parse->GetComment(); }

	bool IsBegin() const { return _w->is_begin; }
	bool IsEnd() const { return _w->is_end; }

	wstring GetWord() { return _w->word; }
	bool IsString() const { return _w->is_string; }

public: // Operators
	void Init() {} // Initializes class
	void Copy(const ParseAll& rhs); // Copies class

private: // Attributes
	SmtPtr<Parse> _parse; // The parser
	list<ParseNode> _words; // Words parsed
	list<ParseNode>::iterator _w; // Iterator to a word
};
#endif